package com.aube.interact.taste.card;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aube.interact.taste.R;
import com.aube.interact.taste.model.OptionItem;
import com.huyn.baseframework.utils.Utils;

/**
 * Created by hill on 16/12/12.
 */

public class VoteOptionViewUp extends LinearLayout {
    private final String TAG = "Aube/VoteOptionViewUp";
    private Context mContext;

    public LinearLayout mLinearLy;
    public FrameLayout mPercentLy;
    public ImageView mVoteImg;
    public TextView mOptionName;
    public TextView mPercentText;
    private View mDivisionLine;
    public View mPercentLine;

    public VoteOptionViewUp(Context context) {
        this(context, null);
    }
    public VoteOptionViewUp(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public VoteOptionViewUp(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
    }

    public void initView(OptionItem data) {
        setOrientation(VERTICAL);
        setBackground(getResources().getDrawable(R.drawable.bg_option_selected));

        mLinearLy = new LinearLayout(mContext);
        mLinearLy.setOrientation(HORIZONTAL);

        mOptionName = new TextView(mContext);
        mOptionName.setText(data.optionValue);
        mOptionName.setTextColor(getResources().getColor(R.color.lightblack));
        mOptionName.setTextSize(12);
        mOptionName.setMaxLines(2);
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER_VERTICAL;
        params.weight = 1;
        mLinearLy.addView(mOptionName, params);

        mPercentText = new TextView(mContext);
        mPercentText.setTextColor(getResources().getColor(R.color.lightblack));
        mPercentText.setTextSize(12);
        params = new LayoutParams(Utils.dip2px(mContext, 35), ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER_VERTICAL;
        mLinearLy.addView(mPercentText, params);

        mVoteImg = new ImageView(mContext);
        params = new LayoutParams(getResources().getDimensionPixelOffset(R.dimen.optionselect_size), getResources().getDimensionPixelOffset(R.dimen.optionselect_size));
        params.leftMargin = Utils.dip2px(mContext, 5);
        params.gravity = Gravity.CENTER_VERTICAL;
        mLinearLy.addView(mVoteImg, params);

        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.dip2px(mContext, 38));
        addView(mLinearLy, layoutParams);

        mPercentLy = new FrameLayout(mContext);

        mDivisionLine = new View(mContext);
        mDivisionLine.setBackgroundColor(getResources().getColor(R.color.grey_60));
        FrameLayout.LayoutParams fParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.dip2px(mContext, 0.5f));
        fParams.gravity = Gravity.CENTER_VERTICAL;
        mPercentLy.addView(mDivisionLine, fParams);

        mPercentLine = new View(mContext);
        mPercentLine.setBackgroundColor(getResources().getColor(R.color.vote_Percent_H));
        fParams = new FrameLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
        mPercentLy.addView(mPercentLine, fParams);

        layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.dip2px(mContext, 2));
        addView(mPercentLy, layoutParams);
    }
}
